<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <body>

        <ui:composition template="./productionReport.xhtml">

            <ui:define name="tabContent">

                <p:panel header="Theo tháng">
                    <h:form>
                        Mạng
                        <p:selectManyCheckbox value="#{productionOfBroadcastBean.selectedProviders}">
                            <f:selectItem itemLabel="Mobifone" itemValue="smsgate_mobifone"/>
                            <f:selectItem itemLabel="Vinaphone" itemValue="smsgate_vinaphone"/>
                            <f:selectItem itemLabel="Viettel" itemValue="smsgate_viettel"/>
                        </p:selectManyCheckbox>

                        <br/>

                        <p:selectOneRadio value="#{productionOfBroadcastBean.reportType}">
                            <f:selectItem itemLabel="Theo tháng" itemValue="#{productionOfBroadcastBean.BY_MONTH}"/>
                            <f:selectItem itemLabel="Theo ngày" itemValue="#{productionOfBroadcastBean.BY_DAY}"/>
                            <p:ajax event="change" update="byMonth byDay" process="@this"/>
                        </p:selectOneRadio>

                        <br/>

                        <h:panelGrid id="byMonth">
                            <h:panelGrid columns="10" rendered="#{productionOfBroadcastBean.reportType == productionOfBroadcastBean.BY_MONTH}">
                                Tháng
                                <p:selectOneMenu value="#{productionOfBroadcastBean.month}">
                                    <f:selectItem itemLabel="01" itemValue="01"/><f:selectItem itemLabel="02" itemValue="02"/>
                                    <f:selectItem itemLabel="03" itemValue="03"/><f:selectItem itemLabel="04" itemValue="04"/>
                                    <f:selectItem itemLabel="05" itemValue="05"/><f:selectItem itemLabel="06" itemValue="06"/>
                                    <f:selectItem itemLabel="07" itemValue="07"/><f:selectItem itemLabel="08" itemValue="08"/>
                                    <f:selectItem itemLabel="09" itemValue="09"/><f:selectItem itemLabel="10" itemValue="10"/>
                                    <f:selectItem itemLabel="11" itemValue="11"/><f:selectItem itemLabel="12" itemValue="12"/>
                                </p:selectOneMenu>
                                Năm
                                <p:selectOneMenu value="#{productionOfBroadcastBean.year}">
                                    <f:selectItem itemLabel="2011" itemValue="2011"/>
                                    <f:selectItem itemLabel="2012" itemValue="2012"/>
                                    <f:selectItem itemLabel="2013" itemValue="2013"/>
                                </p:selectOneMenu>
                                <p:commandButton ajax="false" value="Xem báo cáo" action="#{productionOfBroadcastBean.report()}" onclick="processingDialog.show()"
                                                 onsuccess="processingDialog.hide()"/>
                                <p:commandButton ajax="false" value="Xem tháng này" action="#{productionOfBroadcastBean.reportOfThisMonth()}" onclick="processingDialog.show()"
                                                 onsuccess="processingDialog.hide()"/>
                                <p:commandButton ajax="false" value="Xem tháng trước" action="#{productionOfBroadcastBean.reportOfLastMonth()}" onclick="processingDialog.show()"
                                                 onsuccess="processingDialog.hide()"/>
                            </h:panelGrid>
                        </h:panelGrid>

                        <h:panelGrid id="byDay">
                            <h:panelGrid columns="10" rendered="#{productionOfBroadcastBean.reportType == productionOfBroadcastBean.BY_DAY}">
                                Ngày
                                <p:calendar value="#{productionOfBroadcastBean.day}" pattern="dd/MM/yyyy" timeZone="Asia/Saigon" navigator="true"
                                            required="true" requiredMessage="Bạn chưa chọn ngày"/>
                                <p:commandButton ajax="false" value="Xem báo cáo" action="#{productionOfBroadcastBean.reportByDay()}" onclick="processingDialog.show()"
                                                 onsuccess="processingDialog.hide()"/>
                                <p:commandButton ajax="false" value="Xem hôm nay" action="#{productionOfBroadcastBean.reportOfToday()}" onclick="processingDialog.show()"
                                                 onsuccess="processingDialog.hide()"/>
                            </h:panelGrid>
                        </h:panelGrid>

                        <p:poll autoStart="true" update="tableForm" interval="5" widgetVar="poll" 
                                rendered="#{productionOfBroadcastBean.isProcessing}"
                                stop="#{!productionOfBroadcastBean.isProcessing}" listener="#{productionOfBroadcastBean.checkProgress()}"/>
                    </h:form>
                    <br/>

                    <h:form id="tableForm">

                        Sản lượng broadcast của tháng #{productionOfBroadcastBean.month} năm #{productionOfBroadcastBean.year} 

                        <p:dataTable value="#{productionOfBroadcastBean.list}" var="userItem" resizableColumns="true">
                            <p:column headerText="Người vận hành">
                                #{userItem.username}
                            </p:column>

                            <p:column headerText="Sản lượng">
                                <p:dataTable value="#{userItem.productionOfSyntax}" var="syntaxItem" resizableColumns="true">
                                    <f:facet name="header">  
                                        Tổng: #{userItem.totalProduction}
                                    </f:facet>
                                    <p:column>
                                        #{syntaxItem.syntax}
                                    </p:column>

                                    <p:column>
                                        #{syntaxItem.production}
                                    </p:column>
                                </p:dataTable>
                            </p:column>
                        </p:dataTable>
                    </h:form>

                </p:panel>

                <p:scrollPanel  rendered="#{productionOfBroadcastBean.unmatchSmses.size() > 0}">
                    <ui:repeat value="#{productionOfBroadcastBean.unmatchSmses}" var="item">
                        #{item} <br/>
                    </ui:repeat>
                    
                </p:scrollPanel>

            </ui:define>

        </ui:composition>

    </body>
</html>

